﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

namespace Maticsoft.Web.Admin.Advert
{
    public partial class list : PageBase
    {
        string key = string.Empty;

        BLL.Advert bll = new BLL.Advert();
        protected void Page_Load(object sender, EventArgs e)
        {
            Check("Advert", "read");

            if (!string.IsNullOrEmpty(Request.QueryString["key"]))
            {
                key = Request.QueryString["key"];
            }
            if (!IsPostBack)
            {
                BindData();
            }
        }

        private void BindData()
        {
            string strWhere = "IsActive=1";
            if (!string.IsNullOrEmpty(key))
            {
                strWhere += " and AdvertName like '%" + key + "%'";
            }
            int recordCount = bll.GetRecordCount(strWhere);
            AspNetPager1.RecordCount = recordCount;
            DataSet ds = bll.GetListByPage(strWhere, "OrderNo asc", AspNetPager1.StartRecordIndex, AspNetPager1.EndRecordIndex);

            Repeater1.DataSource = ds.Tables[0].DefaultView;
            Repeater1.DataBind();
        }

        protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
        {
            Response.Redirect(Request.CurrentExecutionFilePath + "?key=" + txtKey.Value);
        }

        protected void LinkButton1_Click(object sender, EventArgs e)
        {
            bll.Delete(int.Parse(txtIds.Value));
            Response.Redirect(Request.CurrentExecutionFilePath + "?key=" + key);
        }

        protected void AspNetPager1_PageChanged(object src, EventArgs e)
        {
            BindData();
        }
    }
}